//
//  SortSecondTableViewCell.m
//  MountEverestFM
//
//  Created by dllo on 15/10/29.
//  Copyright © 2015年 chenn. All rights reserved.
//

#import "SortSecondTableViewCell.h"
#import "SortCollectionViewCell.h"
@implementation SortSecondTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.flowLayout=[[UICollectionViewFlowLayout alloc]init];
        self.collectionView=[[UICollectionView alloc]initWithFrame:self.contentView.bounds collectionViewLayout:self.flowLayout];
         self.collectionView.backgroundColor=[UIColor whiteColor];
        self.collectionView.delegate=self;
        self.collectionView.dataSource=self;
        [self.contentView addSubview:self.collectionView];
        [self.collectionView registerClass:[SortCollectionViewCell class] forCellWithReuseIdentifier:@"sortCollection"];
        
    }
    return self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.cellArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SortCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"sortCollection" forIndexPath:indexPath];

    cell.lable.text=[[self.cellArr objectAtIndex:indexPath.row] objectForKey:@"title"];

    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[[self.cellArr objectAtIndex:indexPath.row] objectForKey:@"coverPath"]] placeholderImage:[UIImage imageNamed:@"find_hotUser_following@3x.png"]];
    return cell;
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
   NSString *str1= [[self.cellArr objectAtIndex:indexPath.row] objectForKey:@"title"];
    NSNumber *num1=[[self.cellArr objectAtIndex:indexPath.row]objectForKey:@"id"];
    self.title=str1;
    self.num=num1;
    self.block();
    
}



-(void)layoutSubviews
{
    [super layoutSubviews];
    


    self.collectionView.frame=self.contentView.bounds;
    self.collectionView.scrollEnabled=NO;
    self.flowLayout.itemSize=CGSizeMake(self.contentView.bounds.size.width/2-FM_Screen_Pts_Height*10, self.contentView.bounds.size.height/3-FM_Screen_Pts_Height*10);
    self.flowLayout.sectionInset=UIEdgeInsetsMake(1,1,1,1);
//    self.flowLayout.scrollDirection=UICollectionViewScrollDirectionHorizontal;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    if (selected) {
        self.backgroundColor = Cell_Selected_Color;
    }else{
        self.backgroundColor = [UIColor whiteColor];
    }
}






/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
